#!/bin/bash

create() {
    docker run -d --name $1             \
        -v $workpath:/works -w /works   \
        -p $2:$2 --dns 3.3.3.3          \
        --restart=always                \
        $image_name php $1.php start
}


run() {
    case "$3" in
        create)
            create $1 $2
            ;;
        rm)
            docker rm -f $1
            ;;
        sh)
            docker exec -it $1 bash
            ;;
        log)
            docker logs $1
            ;;
        restart)
            docker stop $1
            docker start $1
            ;;
        *)
            docker exec $1 php $1.php $3
            ;;
    esac
}

image_name="${IMG_NAME-docker.cat/workerman}"
workpath=${WORK_PATH-$PWD}

case "$1" in
    ws|websocket)
        run websocket 4236 ${2-create}
        ;;
    pub|publish)
        run publish 4237 ${2-create}
        ;;
    sub|subscribe)
        run subscribe 2206 ${2-create}
        ;;
    *)
        echo '不支持命令...'
        ;;
esac

